<%@page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="/teleweb/common/global.jsp" %>

<%@page import="com.cndatacom.teleweb.fileupload.been.FileUpload"%>
<%@page import="com.cndatacom.teleweb.util.FileUtil"%>
<%@page import="org.apache.struts2.ServletActionContext"%>
<%@page import="java.io.File"%>


<%
	String sAttachNum = request.getParameter("attachNum");

	//获取服务器资源列表
	String path = ServletActionContext.getServletContext().getRealPath("/") + "serverfiles";
	File[] fileArray = FileUtil.getFoldFileList(path);
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>中国通信服务</title>
<link href="teleweb/css/ztf.css" rel="stylesheet" type="text/css" />
<link href="teleweb/css/roll.css" rel="stylesheet" type="text/css" />
<link href="teleweb/css/content.css" rel="stylesheet" type="text/css" />
<link href="teleweb/css/upload-component.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="teleweb/js/upload.js"></script>
<script type="text/javascript" src="teleweb/js/submitFunctions.js"></script>
<script language="javascript" type="text/javascript" src="js/My97DatePicker/WdatePicker.js"></script>

<script>
function initData() {
	var attachNum = "${attachNum}";
	if(attachNum==null || attachNum=="") {
		document.getElementById("attachnum").value = "<%=sAttachNum%>";
	}
	
	var docTime = "${knowledgeShare.uploadDate}";
	var nowTime = getNowTime();
	if(docTime==null || docTime=="") {
		document.getElementById("pubdate").value = nowTime;
	}
	
	var serverFileName = "${knowledgeShare.filePath}";
	if(serverFileName.indexOf("serverfiles") >= 0) {
		var fileName = serverFileName.substring(serverFileName.indexOf("/")+1);
		//alert(fileName);
		document.getElementById("serverfile").value = fileName;
	}
}
function window.onbeforeunload(){
	if("${addOrEdit}" == "edit") {
		
		var serverfile = document.getElementById("serverfile").value;
		var uploads = document.getElementById("uploads").innerHTML;
		if(serverfile == "-----------请选择-----------" || serverfile == "") {
			if(uploads == null || uploads == "" || uploads == "<UL></UL>") {
				return "修改时不能将附件置空。";
			}
		}
	}
}
//Form重置
function formReset() {
	pubForm.reset();
}
function validData() {
	var title = document.getElementById("filename").value;
	var date = document.getElementById("pubdate").value;
	if(title == "") {
		alert("文档名称不能为空！")
		return false;
	}else if(date == "") {
		alert("请选择上传日期！");
		return false;
	}
	document.getElementById("random").value = document.getElementById("randomfolder").value;
	
	var serverfile = document.getElementById("serverfile").value;
	var uploads = document.getElementById("uploads").innerHTML;
	if(serverfile == "-----------请选择-----------" || serverfile == "") {
		if(uploads == null || uploads == "" || uploads == "<UL></UL>") {
			alert("附件不能为空！");
			return false;
		}
	}
	pubForm.submit();
}
</script>

</head>
<body onload="initData();initAttach('${knowledgeShare.filePath}','${knowledgeShare.realName}')">

<table width="960" border="0" align="center" cellpadding="0" cellspacing="0">
  <!-- 主体table -->
  <%request.setAttribute("panel","KS");%>
  <%@ include file="/teleweb/common/include/header.jsp" %>
  <tr>
    <!---首页内容--->
    <td class="new_indexcontent">
    <div class="new_stars">
    <div class="new_weizhi">你现在所在的位置：<a href="index">首页</a>><a href="#">知识共享</a></div>
    </div>
    <!---圆角--->
    <div class="box-cir3">
			<div class="t_l"></div>
			<div class="t_m"></div>
			<div class="t_r"></div>
			<div class="m_l"></div>
			<div class="m_m1">
    <!---标题内容--->
			<div class="new_heading1">
            <h3>知识共享</h3>
            </div>
            <div class="new_textform">
            <form name="pubForm" action="knowledgepub-edit" method="post">
            	<input type="hidden" name="serverpath" value="serverfiles">
            	<input type="hidden" name="knowledgeShare.id" value="${knowledgeShare.id}">
            	<input type="hidden" name="random" id="random">
            	<input type="hidden" name="attachnum" value="${attachNum}">
            	<input type="hidden" name="allowType" id="allowtype" value="pdf">
            	<table cellpadding="0" cellspacing="0">
            		<tr>
            			<td class="new_textlable"><span class="new_lable">文档名称</span><span class="new_redstar">*</span></td>
            			<td><input id="filename" name="knowledgeShare.displayName" value="${knowledgeShare.displayName}" type="text" class="new_text"></td>
            		</tr>
            		<tr>
            			<td class="new_textlable"><span class="new_lable">上传日期</span><span class="new_redstar">*</span></td>
            			<td>
            			<input class="Wdate" type="text" name="knowledgeShare.uploadDate" value="${fn:substring(knowledgeShare.uploadDate, 0, 19)}" id="pubdate" style="padding-left:4px;width:150" onClick="WdatePicker({skin:'YcloudRed',dateFmt:'yyyy-MM-dd HH:mm:ss'})"></td>
            		</tr>
            		<tr>
            			<td class="new_textlable"><span class="new_lable">服务器文件</span><span class="new_redstar">*</span></td>
            			<td>
            				<select name="serverfile" id="serverfile">
                				<option value="" selected>-----------请选择-----------</option>
                				
                				<% 
                				for(int i=0; i<fileArray.length; i++) {
                					File file = fileArray[i];
                					String name = file.getName();
                				%>
                					<option value='<%=name %>'><%=name %></option>
                				<% 
                				}
                				%>
                				
    							
							</select>
						</td>
            		</tr>
            	</table>
            </form>
            
            <div style="color:red"><s:fielderror><s:param>attach</s:param></s:fielderror></div>
            <upload:load></upload:load>
            
            <table>
            	<tr>
            		<td class="new_textlable"></td>
            		<td align="center">
    					<div class="new_btform">
    						<button id="saveBnt" class="new_btforml" onclick="validData()">保存</button>
    						<button id="resetBnt" onclick="formReset();">重置</button>
    					</div>
            		</td>
            	</tr>
            </table> 
			             
            </div>                              
			</div>
			<div class="m_r"></div>
			<div class="b_l"></div>
			<div class="b_m"></div>
			<div class="b_r"></div>
		</div>
    </td>
  </tr>
  <%@ include file="../common/include/tail.jsp"%>
</table>
</body>
</html>
